package com.googlecode.autopp;

import com.googlecode.autopp.driver.RandomDriver;

/**
 * Class used for creating objects and filling its by data provided by drivers.
 */
public final class Populator {

    // driver used for populating objects.
    private Driver driver;

    /**
     * Constructor. RandomDriver is chosen for default.
     */
    public Populator() {
        this(new RandomDriver());
    }

    /**
     * Constructor.
     * 
     * @param driver
     *            Driver used for populating objects.
     */
    public Populator(Driver driver) {
        this.driver = driver;
    }

    /**
     * Crates and fills object.
     * 
     * @param <T> Type of created object.
     * @param clazz Type of created object.
     * 
     * @return Populated object.
     */
    public <T> T fill(Class<T> clazz) {
        return driver.createAndPopulateObject(new ObjectContext<T>(clazz, 0));
    }
}
